#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>

int
main(int argc, char *argv[])
{
    int i ,j,p;
    int m =1024;
    int size = m*m;
    double *A=(double *)malloc(sizeof(double)*size);
    double *B=(double *)malloc(sizeof(double)*size);
    double *C=(double *)malloc(sizeof(double)*size);

    for (i = 0; i < size; i++)
  {
    A[i] = i % 3 + 1; // (rand() % 100) / 100.0;
  }

  for (i = 0; i < size; i++)
  {
    B[i] = i % 3 + 1; //(rand()%100)/10.0;
  }

  for (i = 0; i < size; i++)
  {
    C[i] = 0.1;
  }
    int rc = fork();
    if (rc < 0) {
        // fork failed; exit
        fprintf(stderr, "fork failed\n");
        exit(1);
    } else if (rc == 0) {
        // child (new process)
        printf("hello, I am child (pid:%d)\n", (int) getpid());
            for(i = 0; i < m;i ++)
        {
                for(j = 0;j < m;j ++)
                {
                    for(p = 0; p < m; p ++)
                    {
                        C[i*m+j]+=A[i*m+p]*B[p*m+j];
                    }
                }
        }
    } else {
        // parent goes down this path (original process)
        printf("hello, I am parent of %d (pid:%d)\n",
	       rc, (int) getpid());
           for(i = 0; i < m;i ++)
        {
                for(j = 0;j < m;j ++)
                {
                    for(p = 0; p < m; p ++)
                    {
                        C[i*m+j]+=A[i*m+p]*B[p*m+j];
                    }
                }
        }
    }
    return 0;
}